<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>商品列表</title>
<link rel="stylesheet" href="{{ asset('admin_style/css/pintuer.css') }}">
   <link rel="stylesheet" href="{{ asset('admin_style/css/admin.css') }}">
    <script src="{{asset('admin_style/js/jquery.js')}}"></script>
    <script src="{{asset('admin_style/js/pintuer.js')}}"></script>
<link rel="stylesheet" href="{{asset('admin_style/css/style.css')}}">
<!--<link rel="stylesheet" href="css/ace.min.css">-->
<script src="{{asset('admin_style/js/layer/layer.js')}}"></script>
</head>
<body>
<div id="box">
<form method="post" action="" id="listform">
<input type="hidden" id="cid_1" value="{{$arr[0]}}">
<input type="hidden" id="san_1" value="{{$arr[1]}}">
<input type="hidden" id="shang_1" value="{{$arr[2]}}">
<input type="hidden" id="input_1" value="{{$arr[3]}}">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 商品列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
			    <div class="border-b border-bno clearfix">
			      <a href="add-product.html" class="button bg-yellow button-small"><span class="icon-plus"></span>添加新商品</a>
			     </div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <!--<li> <a class="button border-main icon-plus-square-o" href="add.html"> 发布文章</a> </li>-->
          <li>
            <select id="cid" class="input" style="width:150px; line-height:17px;" onchange="changesearch()">
              <option value="0">所有分类</option>
              @foreach($cate as $v)
                <option value="{{$v->cate_id}}">{{$v->cate_name}}</option>
              @endforeach
            </select>
          </li>
       
          <li>
            <select id="san" class="input" style="width:100px; line-height:17px;" onchange="changesearch()">
              <option value="0">所有商品</option>
              <option value="1">精品</option>
              <option value="2">特价</option>
              <option value="3">热销</option>
            </select>
          </li>
          <li>
            <select id="shang" class="input" style="width:100px; line-height:17px;" onchange="changesearch()">
              <option value="0">全部</option>
              <option value="1">上架</option>
              <option value="2">下架</option>
            </select>
          </li>
        <li>
          <input type="text" placeholder=""  id="input" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 查询</a></li>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">编号</th>
        <th>产品名称</th>
        <th>单价</th>
        <th>分类</th>
        <th>库存</th>
        <th>上架</th>
        <th>精品</th>
        <th>特价</th>
        <th>热销</th>
        <th width="310">操作</th>
      </tr>
      @foreach($data as $v)
        <tr>
          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="check" value="{{$v->g_id}}" />{{$v->g_id}}</td>
          <td>{{$v->g_name}}</td>
          <td>{{$v->g_original_price}}</td>
          <td>{{$v->cate_name}}</td>
          <td>{{$v->g_reper}}</td>
          <td>{{$v->g_putaway}}</td>
          <td>{{$v->g_boutique}}</td>
          <td>{{$v->g_special}}</td>
          <td>{{$v->g_hot}}</td>
          <td><div class="button-group"><a class="button border-yellow" href="add-product.html"><span class="icon-edit (alias)"></span>编辑</a><a class="button border-main" href="javascript:void(0)" onclick="attr_del({{$v->g_id}})"><span class="icon-eye"></span>设置商品规格 </a> <a class="button border-red" href="{{ url('admin/onedels/'.$v->g_id)}}" onclick="return del(1,1,1)"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr>
      @endforeach
      <tr>
        <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checked" onclick="checkAll()"/>
          全选 </td>
        <td colspan="10" style="text-align:left;padding-left:20px;"><a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="dels()"> 批量删除</a> 
      </tr>
    </table>
    <center><div class="fenye">{{$data->links()}}</div></center>
  </div>
</form>
</div>
<script type="text/javascript">
function attr_del(id){
  if(confirm("您确定要从新设置规格吗？")){
    location.href = "{{ url('goods/goods_attr')}}/"+id;
  }
}


window.onload=function(){
  var cid_1     = document.getElementById("cid_1").value;
  var san_1     = document.getElementById("san_1").value;
  var shang_1   = document.getElementById("shang_1").value;
  var input_1   = document.getElementById("input_1").value;
  var arr = new Array(cid_1,san_1,shang_1,input_1);
  document.getElementById("cid").value = arr[0];
  document.getElementById("san").selectedIndex = arr[1];
  document.getElementById("shang").selectedIndex = arr[2];
  document.getElementById("input").value = arr[3];
}
//搜索
function changesearch(){
  var cid     = document.getElementById("cid").value;
  var san     = document.getElementById("san").value;
  var shang   = document.getElementById("shang").value;
  var input   = document.getElementById("input").value;
  var arr = new Array(cid,san,shang,input);
  var xh      = new XMLHttpRequest();
  xh.open('get',"{{ url('admin/search/')}}/"+arr,true);
  xh.send();
  xh.onreadystatechange = function(){
    if(xh.readyState == 4 && xh.status==200){
      document.getElementById('box').innerHTML=xh.responseText;
      document.getElementById("cid").value = arr[0];
      document.getElementById("san").selectedIndex = arr[1];
      document.getElementById("shang").selectedIndex = arr[2];
      document.getElementById("input").value = arr[3];
    }
  }
}


//单个删除
function del(id,mid,iscid){
	if(confirm("您确定要删除吗?")){
		location.href = "{{ url('admin/goodsdel')}}/"+id;
	}
}

//全选
function checkAll(){
  var str = document.getElementsByName('check');
  var mo = document.getElementById('checked');
  var status = mo.checked;
  if(status){
    for(var i=0;i<str.length;i++){
      str[i].checked=true;
    }
  }else{
    for(var i=0;i<str.length;i++){
      str[i].checked=false;
    }
  }
}

//批量删除
function dels(){
  var check = document.getElementsByName('check');
  var ids=[];
  for(var i=0;i<check.length;i++){
    if(check[i].checked){
      ids.push(check[i].value);
    }
  }
  var str = ids.join(',');
    var xh      = new XMLHttpRequest();
    xh.open('get',"{{ url('admin/goodsdels/')}}/"+str,true);
    xh.send();
    xh.onreadystatechange = function(){
        if(xh.readyState == 4 && xh.status==200){
            document.getElementById('box').innerHTML=xh.responseText;
        }
    }
}

</script>
</body>
</html>
